package com.myk.game.heroscuffle.signs;

import com.myk.game.heroscuffle.game.Hero;
import com.myk.game.heroscuffle.game.Sign;

/**
 * 记录数量类标记
 */
public abstract class CountSign extends Sign {

    public final int SIGN_MAX;
    public int count;

    public CountSign(String SIGN_NAME, int SIGN_MAX) {
        super(SIGN_NAME);
        this.SIGN_MAX = SIGN_MAX;
    }

    @Override
    public String getObviousName() {
        return "/" + SIGN_NAME + "x:" + count + "/";
    }

    @Override
    protected final void paste(Hero hostHero) {
        this.hostHero = hostHero;
        this.game = hostHero.game;
        boolean has = false;
        for (Sign sign : hostHero.SIGNS) {
            if (sign.getClass() == this.getClass()) { //这类标记如果原来已经存在，新增时只增加数量
                if (((CountSign) sign).count < SIGN_MAX) {
                    ((CountSign) sign).count = ((CountSign) sign).count + 1;
                }
                has = true;
            }
        }
        if (!has) {
            count = 1;
            game.ui.sleepShortly();
            hostHero.SIGNS.add(this);
            onPaste();
        }
    }

    protected void onPaste() {

    }

    @Override
    protected final void update() {
        if (count > 0) {
            onUpdate();
        }
        /*else {
            //数量为0时解绑
            Sign waitRemove = null;
            for (Sign sign : hostHero.SIGNS) {
                if (sign.getClass() == this.getClass()) {
                    waitRemove = sign;
                }
            }
            if (waitRemove != null) {
                hostHero.SIGNS.remove(waitRemove);
            }
        }*/
    }

    protected void onUpdate() {

    }

    @Override
    protected void remove(Hero hostHero) {
        hostHero.SIGNS.remove(this);
        onRemove();
    }

    protected void onRemove() {

    }
}
